-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Pyomo Model Plot #2251
[WIP] Pyomo Model Plot #2251
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2251 +/- ##
==========================================
+ Coverage 83.07% 83.09% +0.01%
==========================================
Files 607 608 +1
Lines 77018 77100 +82
==========================================
+ Hits 63984 64063 +79
- Misses 13034 13037 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really neat!
import networkx as nx | ||
import pyomo.environ as pe | ||
import plotly.graph_objects as go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the attempt_import
stuff around networkx and plotly here?
@@ -201,6 +201,7 @@ def _print_deps(self, deplist): | |||
'ipython', # contrib.viewer | |||
'matplotlib', | |||
'networkx', # network, incidence_analysis, community_detection | |||
'plotly', # pyomo.util.graph.plot_pyomo_model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this list in alphabetical order
def graph_from_pyomo(m: _BlockData, | ||
include_objective: bool = True, | ||
active: bool = True) -> nx.Graph: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a short docstring?
def plot_pyomo_model(m: _BlockData, | ||
include_objective: bool = True, | ||
active: bool = True, | ||
plot_title: Optional[str] = None, | ||
bipartite_plot: bool = False, | ||
show_plot: bool = True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a short docstring?
There was some discussion at the developers meeting about whether this belongs in |
Closing this for now. This PR inspired some great discussion around standardizing graph representations of Pyomo models in #2272 but we don't currently have the resources to get those ideas implemented in this PR like we wanted. This plotting functionality has been incorporated in |
Summary/Motivation:
This PR adds a function to create a Plotly plot of the graph of a pyomo model. It is "interactive" in the sense that you get information about a component if you hover over the corresponding node.
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: